<?php

$this->breadcrumbs = array(
    '订单中心' => array('orders/admin'),
    '查看',
);
Yii::app()->clientScript->registerScript('tabs', '
    $( "#tabs" ).tabs();
    ');
?><div class="box corners shadow">
    <div class="box-header">
        <h2>查看→订单 #<?php echo $model->order_number; ?></h2></h2>
        <div class="box-header-ctrls">	
            <a href="javascript:void(null);" title="" class="close"><!-- --></a>
        </div>
    </div>
    <div class="box-content" id="contacts-1a">
        <div class="inbox-sf">
            <?php
            echo CHtml::link('<span>删除</span>', '#', array(
                'submit' => array('delete'),
                'class' => 'button black fr',
                'confirm' => '您确定要删除吗?'
            ));
            ?> 
            <a class="button black fr" href=" <?php echo $this->rewriteCreateUrl('admin'); ?>"><span>管理</span></a>
        </div>

        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">客户信息</a></li>
                <li><a href="#tabs-2">支付信息</a></li>
                <li><a href="#tabs-3">订单信息</a></li>
                <li><a href="#tabs-4">产品信息</a></li>
                <li><a href="#tabs-5">订单处理</a></li>
            </ul>
            <div id="tabs-1">
                <?php
                //客户信息
                $this->widget('zii.widgets.CDetailView', array(
                    'data' => $customer,
                    'cssFile' => '',
                    'htmlOptions' => array('class' => 'tablelist'),
                    'attributes' => array(
                        'first_name',
                        'last_name',
                        'email',
                        'ip',
                        'phone',
                        'country',
                        'city',
                        'address',
                        'msn',
                    ),
                ));
                ?>
            </div>
            <div id="tabs-2">
                <?php
                //支付信息
                if ($payment) {
                    $this->widget('zii.widgets.CDetailView', array(
                        'data' => $payment,
                        'cssFile' => '',
                        'htmlOptions' => array('class' => 'tablelist'),
                        'attributes' => array(
                            'business',
                            'receiver_email',
                            'receiver_id',
                            'verify_sign',
                            'payer_id',
                            'txn_id',
                            'payment_status',
                            'payer_email',
                            'payment_amount',
                            'payment_currency',
                            'payment_fee',
                            'payment_date',
                            'memo',
                            'address_country',
                            'address_city',
                            'address_street',
                            'address_zip',
                            'contact_phone',
                            'address_status',
                            'first_name',
                            'last_name',
                            'payer_status',
                            'pay_type',
                        ),
                    ));
                } else {
                    echo 'PAYPAL信息为空';
                }
                ?>
            </div>
            <div id="tabs-3">
                <?php
                //订单总信息
                $this->widget('zii.widgets.CDetailView', array(
                    'data' => $model,
                    'cssFile' => '',
                    'htmlOptions' => array('class' => 'tablelist'),
                    'attributes' => array(
                        'order_number',
                        'site_key',
                        'currency_tag',
                        'total_price',
                        'comment',
                        'coupon',
                        'offset',
                        'order_date:datetime',
                        'pay_status',
                        'status',
                        'uid',
                        'pay_type',
                    ),
                ));
                ?>
            </div>
            <div id="tabs-4">
                <?php
                //产品详单
                $i = 0;
                foreach ($items as $item) {
                    ++$i;
                    echo "<h2>产品$i</h2>";
                    $input = '';
                    foreach (unserialize($item->input) as $key => $input_v) {
                        $input .= "<b>$key:</b> $input_v <br/>";
                    }
                    $item->input = $input;
                    $this->widget('zii.widgets.CDetailView', array(
                        'data' => $item,
                        'cssFile' => '',
                        'htmlOptions' => array('class' => 'tablelist'),
                        'attributes' => array(
                            'game',
                            'game_server',
                            'input:html',
                            'product_type',
                            'name',
                            'info',
                            'price',
                            'num',
                            'gold_num',
                        ),
                    ));
                }
                ?>
            </div>
            <div id="tabs-5">
                <ul style="list-style: none;font-size: 14px;">
                    <li>当前订单状态：<span id="now-status"><?php echo Yii::app()->params['orderStatus'][$model->status]; ?></span></li>
                    <li>
                        更新订单状态：<?php echo CHtml::dropDownList('status', $model->status, Yii::app()->params['orderStatus'], array('onchange' => "updateOrderStatus('$model->order_number', this)")); ?>
                        <span id="loading" style="display: none;">处理中......</span>
                    </li>

                </ul>
            </div>
        </div>


    </div>
</div>
<script>
    function updateOrderStatus(order_number, obj){
        $('#loading').show();
        var status = $(obj).val();
        $.post("<?php echo $this->createUrl('api');?>", {order_number:order_number, status:status}, function(data){
            if(data==1){
                $("#now-status").html($(obj).find('option:selected').text());
            }
            $('#loading').hide();
        });
    }
</script>